<?php

namespace app\api\controller\club;

use app\common\controller\ClubApi;

/**
 * 俱乐部小程序接口
 */
class Coach extends ClubApi
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @api {get, post} /api/club/coach/detail 教练详情页
     * @apiGroup 教练
     *
     * @apiParam {String} teacher_id 教练ID
     */
    public function detail($teacher_id='')
    {
        try{
            $data  = [];
            $data['detail'] = $this->getService()->getCoachDetail($teacher_id);
            return $this->success('成功', $data);
        } catch (\think\exception\HttpResponseException $e){
            throw $e;
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }
    
    /**
     * @api {get, post} /api/club/coach/listcomment 教练评论列表
     * @apiGroup 教练
     *
     * @apiParam {String} teacher_id 教练ID
     */
    public function listcomment($teacher_id='')
    {
        try{
            $data  = [];
            $data['list'] = $this->getService()->getCommentList($teacher_id, '教练');
            return $this->success('成功', $data);
        } catch (\think\exception\HttpResponseException $e){
            throw $e;
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }
    
    /**
     * @api {get, post} /api/club/coach/comment 教练评论
     * @apiGroup 教练
     *
     * @apiParam {String} teacher_id 教练ID
     * @apiParam {String} text 评论内容
     */
    public function comment($text='', $teacher_id='')
    {
        try{
            if(!$text){
                throw new \Exception('评论内容不能为空');
            }
            $data  = [];
            $uid = $this->getService()->getLoginUid();
            $data['id'] = $this->getService()->getCoachAddComment($uid, $teacher_id, $text);
            return $this->success('成功', $data);
        } catch (\think\exception\HttpResponseException $e){
            throw $e;
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }
    
}
